package com.server.rule.component.integrated;

import org.jdom.Element;

import com.server.rule.component.RuleDecision;
import com.server.rule.data.Data;
import com.server.rule.data.ExceptionTypeData;
import com.shared.model.Proposition;
import com.shared.rule.TypeDecision;


/**
 * Decision correspondant à un message destiné à la cible
 * @author queyroi
 *
 */
public class RuleDecisionMessage extends RuleDecisionWithProposition{

	
	protected TypeDecision typeDecision;
	protected String message = "";
	
	public RuleDecisionMessage() {
		super();
		typeDecision = TypeDecision.MESSAGE;
	}
	
	public RuleDecisionMessage(String label) {
		super(label);
		typeDecision = TypeDecision.MESSAGE;
	}
	
	public RuleDecisionMessage(String label,String message){
		this(label);
		this.message = message;
	}
	
	
	
	public Element getXMLElement(){
		Element xmlElement = new Element("Rule");
		xmlElement.setAttribute("type", typeDecision.toString());
		xmlElement.setAttribute("label", label);
		Element child = new Element("Message");
		child.setAttribute("message",message);
		xmlElement.addContent(child);		
		return xmlElement;
	}
	
	public void generateFromXML(Element xmlElement){
		label = xmlElement.getAttributeValue("label");		
		message = xmlElement.getChild("Message").getAttributeValue("message");		
	}
	
	public Proposition createProposition(){
		Proposition proposition = new Proposition();
		proposition.setMessage(message);		
		return proposition;
	}
	
		
	/**
	 * @return the typeDecision
	 */
	public TypeDecision getTypeDecision() {
		return typeDecision;
	}
	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}
	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}
}
